// pages/minePage/countryNumber/countryNumber.js
const app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        uid: '',
        countryInfoArr: [],
        loading: true,
        loadingAll: false,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        wx.setNavigationBarTitle({
            title: '国家数·' + options.checkincountrynum,
        });
        this.setData({
            uid: options.uid,
        });
        this.getCountryInfo();
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},

    getCountryInfo(e) {
        let _that = this;
        wx.request({
            url: app.globalData.rootPath + `cjMap/getCheckinCountryList`,
            method: 'GET',
            header: {
                'content-type': 'application/x-www-form-urlencoded',
            },
            data: {
                // authId: 'bcf82b6392f54843805253387e6985c0',
                authId: app.globalData.authId,
                uid: _that.data.uid || '',
            },
            success: function (res) {
                let checkintimeDay;
                if (res.data.errmsg == '输入页码超出范围') {
                    _that.setData({
                        loadingAll: true,
                        loading: false,
                    });
                } else {
                    for (let i = 0; i < res.data.data.length; i++) {
                        checkintimeDay = res.data.data[i].checkintime.slice(
                            8,
                            10
                        )
                            ? '/' + res.data.data[i].checkintime.slice(8, 10)
                            : '';
                        res.data.data[i].checkintime =
                            res.data.data[i].checkintime.slice(0, 4) +
                            '/' +
                            res.data.data[i].checkintime.slice(5, 7) +
                            checkintimeDay;
                        _that.data.countryInfoArr.push(res.data.data[i]);
                    }
                    _that.setData({
                        countryInfoArr: _that.data.countryInfoArr,
                        loadingAll: true,
                        loading: false,
                    });
                }
            },
        });
    },
});
